﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace Common
{
    /// <summary>
    /// 生成文件名
    /// </summary>
    public static class FileNameCreater
    {
        /// <summary>
        /// 生成当前时间的yyyyMMddHHmmssffff格式字符串
        /// </summary>
        /// <returns></returns>
        public static string ByDateTime()
        {
            return DateTime.Now.ToString("yyyyMMddHHmmssffff");
        }
        /// <summary>
        /// 根据指定的时间格式生成
        /// </summary>
        /// <param name="format"></param>
        /// <returns></returns>
        public static string ByDateTime(string format)
        {
            return DateTime.Now.ToString(format);
        }
        /// <summary>
        /// 根据GUID
        /// </summary>
        /// <returns></returns>
        public static string ByGUID()
        {
            return Guid.NewGuid().ToString();
        }
        /// <summary>
        /// 根据毫秒数
        /// </summary>
        /// <returns></returns>
        public static string ByMillisecondCount()
        {
            Thread.Sleep(100);
            DateTime d1 = DateTime.Now;
            DateTime d2 = new DateTime(1970, 1, 1, 0, 0, 0);
            TimeSpan span = d1 - d2;
            return span.TotalMilliseconds.ToString();
        }
    }
}
